public class ch01 {
    public static void main(String[] args) {
        int[] arr = {100, 200, 300, 400, 500, 600};
        int sum1 = sum(arr), sum2 = sumToEnd(arr, 0);
        System.out.printf("%d and %d are equal.\n", sum1, sum2);
    }

    // recurrent, 递推的
    public static int sum(int[] arr) {
        var sum = 0;
        for (var n : arr) sum += n;
        return sum;
    }

    // recursive, 递归的
    public static int sumToEnd(int[] arr, int cur) {
        if (cur == arr.length) return 0; // 越界代偿
        return arr[cur] + sumToEnd(arr, cur + 1);
    }
}
